var express = require('express');
const bodyParser = require('body-parser')
var router = require('./router/router');
const methodOverride = require('method-override')
var path = require('path');


const app = express();

app.use(bodyParser.json({limit:'100mb'}));
app.use(bodyParser.urlencoded({ limit:'100mb', extended: true }));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(methodOverride())

app.all('*', function(req, res, next) {
  res.header('Access-Control-Allow-Credentials', 'true');
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "X-Requested-With,Content-Type");
  res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
  next();
  });

app.get('/',function(req,res){
  res.send("hello")
})
  ///////
  //挂载路由
app.use(router)

// 配置一个处理 404 的中间件
app.use(function (req, res) {
  res.render('404.html')
})

// 配置一个全局错误处理中间件
app.use(function (err, req, res, next) {
  res.status(500).json({
    err_code: 500,
    message: err.message
  })
})



app.listen('3000', function () {
    console.log('app is running...')
  })